﻿namespace PortableImagingLibrary.UnitTests
{
    using System;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using PortableImagingLibrary.Png.Crc;

    [TestClass]
    public class CrcTest
    {
        [TestMethod]
        public void ValidateCrc32()
        {
            // Arrange
            var reference = new List<Tuple<string, uint>>() {
                new Tuple<string, uint>("a", 3904355907),
                new Tuple<string, uint>("abc", 891568578),
                new Tuple<string, uint>("message digest", 538287487),
                new Tuple<string, uint>("abcdefghijklmnopqrstuvwxyz", 1277644989),
                new Tuple<string, uint>("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 532866770),
                new Tuple<string, uint>("12345678901234567890123456789012345678901234567890123456789012345678901234567890", 2091469426),
                new Tuple<string, uint>("\uFFFE\u0000\u0001\u0002", 2968055525),
                new Tuple<string, uint>("-", 2547889144),
                new Tuple<string, uint>("--", 606868581)
            };

            ICrc crc = CrcFactory.Create();

            // Act
            foreach (var pair in reference) {
                crc.Reset();
                crc.Update(pair.Item1);

                // Assert
                Assert.AreEqual(pair.Item2, crc.CurrentValue);
            }
        }
    }
}
